package com.xyhy.core.utils.media;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;

import javax.imageio.ImageIO;

public class ImageUtils {

  /**
   * 获取图片分辨率
   */
  public static String getResolution(File file) throws IOException {
    BufferedImage image = ImageIO.read(file);
    return image.getWidth() + "x" + image.getHeight();
  }

  /**
   * 获取图片分辨率
   */
  public static String getResolution(InputStream inputStream) throws IOException {
    BufferedImage image = ImageIO.read(inputStream);
    return Optional.ofNullable(image).map(x -> x.getWidth() + "x" + x.getHeight()).orElse(null);
  }

}
